/*
 * Copyright (c) 2025 CAX Conversion Project
 */
package com.comac.ins.isfd.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.comac.ins.common.core.domain.R;
import com.comac.ins.common.mybatis.core.page.TableDataInfo;
import com.comac.ins.isfd.domain.bo.query.FastenerQueryBo;
import com.comac.ins.isfd.domain.vo.FastenerCountObjectVo;
import com.comac.ins.isfd.domain.vo.FastenerImportObjectVo;
import com.comac.ins.isfd.domain.vo.IsfdFastenerCountObjectVo;
import com.comac.ins.isfd.domain.vo.IsfdTreeNodeVo;
import com.comac.ins.isfd.service.IFastenerService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 紧固件controller
 *
 * @author hxloongs
 * @date 2024-7-3
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/fastener")
public class FastenerController {

    @Autowired
    private IFastenerService iFastenerService;

    @SaCheckPermission("isfd:fastener:count")
    @GetMapping("/list/count")
    @Operation(summary = "统计紧固件各类型的数量接口", security = @SecurityRequirement(name = "isfd:fastener:count"))
    public R<List<FastenerCountObjectVo>> listCount() {
        return R.ok(iFastenerService.listCount());
    }

    @SaCheckPermission("isfd:fastener:count")
    @GetMapping("/list/count/{field}")
    @Operation(summary = "统计紧固件各类型的数量接口", security = @SecurityRequirement(name = "isfd:fastener:count"))
    public R<List<IsfdFastenerCountObjectVo>> listCountByListByField(@PathVariable String field) {
        return R.ok(iFastenerService.listCountByListByField(field));
    }

    /**
     * 查询紧固件库数据的树形接口
     */
    @SaCheckPermission("isfd:fastener:tree")
    @GetMapping("/list/tree")
    @Operation(summary = "查询紧固件库数据的树形接口", security = @SecurityRequirement(name = "isfd:fastener:tree"))
    public R<IsfdTreeNodeVo> listTree() {
        return R.ok(iFastenerService.listTree());
    }

    @SaCheckPermission("isfd:fastener:list")
    @PostMapping("/list")
    @Operation(summary = "紧固件分页查询列表接口", security = @SecurityRequirement(name = "isfd:fastener:list"))
    public TableDataInfo<FastenerImportObjectVo> getFastenerList(@RequestBody FastenerQueryBo queryBo) {
        return iFastenerService.queryPageList(queryBo);
    }

}
